package com.ycy.controller.employee;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ycy.pojo.Bank;
import com.ycy.pojo.Employee;
import com.ycy.pojo.Role;
import com.ycy.pojo.Wage;
import com.ycy.service.Role.RoleService;
import com.ycy.service.bank.BankService;

@Controller
public class BankController {

	@Autowired
	BankService service;
	@Autowired 
	private RoleService roleService;
	@RequestMapping("/bank_list")
	public String bankList(HttpServletRequest request,Model m,HttpSession session){
		Employee employee1=(Employee)session.getAttribute("Me");
		Role role=roleService.findByName(employee1.getName());
		if(role.getRole().equals("超级管理员")||role.getRole().equals("管理员") ){
			List<Bank> bankers= service.findall();
			session.setAttribute("Bankers",bankers);
		}else {
		Bank bank=	service.findByName(employee1.getName());
		session.setAttribute("Bankers",bank);
		}
		return "bank_list";
	}
	@RequestMapping("/bank_del")
	public String bankDel(int id,HttpServletRequest request,Model m,HttpSession session){
		int n= service.del(id);
		if(n>0){
			return "ok";
		}else{
			return "fail";
		}
		
	}
	@RequestMapping("/bank_add")
	public String bankAdd(Bank bank,HttpServletRequest request,Model m,HttpSession session){
		return "bank_add";
	}
	@RequestMapping("/do_bank_add")
	public String bankDoAdd(Bank bank,HttpSession session){
		int n= service.add(bank);
		if(n>0){
			return "ok";
		}else{
			return "fail";
		}
	}
	@RequestMapping("/bank_edit")
	public String bankEdit(HttpServletRequest request,Model m,HttpSession session){
		Employee employee= (Employee) session.getAttribute("Me");
		Bank bnk=service.findByName(employee.getName());
		session.setAttribute("Bank", bnk);
		return "bank_edit";
	}
	@RequestMapping("/do_bank_edit")
	public String bankDoEdit(Bank bank,HttpSession session){
		int n= service.edit(bank);
		if(n>0){
			return "ok";
		}else{
			return "fail";
		}
	}
	
	
	
}
